home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Misc / emu / fbzx.lha / fbzx / sound_ahi.c < prev    next >
C/C++ Source or Header  |  2004-08-26  |  2KB  |  110 lines

  1. #include "Z80.h"
  2. #include "computer.h"
  3. #include "emulator.h"
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8.  
  9. #include    <devices/ahi.h>
  10. #include    <proto/alib.h>
  11. #include    <proto/exec.h>
  12.  
  13. char sound_type; // 0=OSS, 1=no sound
  14.  
  15. static struct AHIRequest    *io    = NULL;;
  16. static struct MsgPort        *port    = NULL;
  17. static int    pending    = 0;
  18.  
  19. static UWORD sample_buf[4096];
  20.  
  21. int sound_init(int wfreq,int wbuff) {
  22.  
  23.     struct AHIRequest    *req;
  24.     int bytes,stereo;
  25.  
  26.     if(sound_type==1) { // no sound; simulate 8bits mono
  27.         ordenador.sign=0;
  28.         ordenador.format=0;
  29.         ordenador.channels=1;
  30.         ordenador.channels = 1;
  31.         ordenador.freq=48000;
  32.         ordenador.buffer_len=4800; // will wait 1/10 second
  33.         return (0);        
  34.     }
  35.  
  36.     port    = CreateMsgPort();
  37.     req    = (struct AHIRequest *)CreateIORequest(port, sizeof(*req));
  38.  
  39.     if (req)
  40.     {
  41.         req->ahir_Version    = 4;
  42.  
  43.         if (OpenDevice("ahi.device", 0, (struct IORequest *)req, 0) == 0)
  44.         {
  45.             req->ahir_Std.io_Command    = CMD_WRITE;
  46.             io->ahir_Std.io_Data            = sample_buf;
  47.             req->ahir_Std.io_Offset        = 0;
  48.             req->ahir_Std.io_Length        = 4096*2;
  49.             req->ahir_Type            = AHIST_M16S;
  50.             req->ahir_Frequency    = 48000;
  51.             req->ahir_Volume        = 0x10000;
  52.             req->ahir_Position    = 0x8000;
  53.             req->ahir_Link    = NULL;
  54.  
  55.             io    = req;
  56.  
  57.             bytes=0; //8 bits
  58.             stereo=0; // no stereo
  59.     
  60.            ordenador.sign=-128;
  61.               ordenador.format=2;
  62.             ordenador.channels = 1;
  63.             ordenador.freq=48000;
  64.             ordenador.buffer_len=4096;
  65.  
  66.             return 0;
  67.         }
  68.  
  69.         DeleteIORequest((struct IORequest *)req);
  70.     }
  71.  
  72.     DeleteMsgPort(port);
  73.  
  74.     return -1;    
  75. }
  76.  
  77. void sound_play() {
  78.  
  79.     ordenador.current_buffer=sound[0];
  80.     if(sound_type==1) { // no sound
  81.         TimeDelay(0, 0, 75000); // wait 1/20 second
  82.         return;
  83.     }
  84.  
  85.     if (pending)
  86.         WaitIO((struct IORequest *)io);
  87.  
  88.     CopyMemQuick(sound[0], sample_buf, 4096*2);
  89.     SendIO((struct IORequest *)io);
  90.     pending    = 1;
  91. }
  92.  
  93. void sound_close() {
  94.     if(sound_type==0)
  95.     {
  96.         if (io)
  97.         {
  98.             if (pending)
  99.             {
  100.                 AbortIO((struct IORequest *)io);
  101.                 WaitIO((struct IORequest *)io);
  102.             }
  103.  
  104.             CloseDevice((struct IORequest *)io);
  105.             DeleteIORequest((struct IORequest *)io);
  106.             DeleteMsgPort(port);
  107.         }
  108.     }
  109. }
  110.